import { create, update, remove, query } from '../service/index';
import { getTabBarList } from '../config/TabBarHolder';

export default {

  namespace: 'app',

  state: {
    tabBarList: getTabBarList()
  },

  subscriptions: {
    setup({ dispatch, history }) {
    }
  },

  effects: {
    *updateTabBar({ payload }, { select, put }) {
      const { ids } = payload;
      const tabBarList = yield select(({ app }) => app.tabBarList);
      const newList = tabBarList.map(item => {
        const selected = ids.filter(id => id === item.id);
        if (selected && selected.length > 0) {
          item.visible = true;
        }
        return item;
      });

      yield put({
        type: 'update',
        payload: {
          tabBarList: newList,
        }
      })
    }
  },

  reducers: {
    update(state, action) {
      return { ...state, ...action.payload };
    },
  }

};
